//
//  SunCheckGetMoneyVC.m
//  Xspcf
//
//  Created by sunshine on 16/10/30.
//  Copyright © 2016年 小小算盘. All rights reserved.
//

#import "SunCheckGetMoneyVC.h"
#import "SunChangePayCodeVC.h"
#import "SunRecordVC.h"
#import "JxWebVC.h"

@interface SunCheckGetMoneyVC ()<UITextFieldDelegate>
{
    UILabel *_timeLabel;
    UILabel *_feeLabel;
    UILabel *_receiveMoneyLabel;
}
@end

@implementation SunCheckGetMoneyVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"我要提现";
    self.view.backgroundColor = BACKGROUND;
    [self creatUI];
    // Do any additional setup after loading the view.
}

- (void)creatUI{
    UIView *view = [[UIView alloc]init];
    [self.view addSubview:view];
    view.backgroundColor = WHITE;
    [view lt_Top:SunEdgesMake(Y(22), 0, 0, Y(74)) to:nil save:YES];
    UILabel *label = [[UILabel alloc]init];
    [view addSubview:label];
    [label lt_setLeft:X(20) to:nil save:YES];
    [label lt_YcenterTo:nil save:YES];
    label.text = @"提现至";
    label.textColor = GRAY;
    label.font = [UIFont systemFontOfSize:16];
    UIImageView *imgV = [[UIImageView alloc]init];
    [view addSubview:imgV];
    [imgV lt_YcenterTo:nil save:YES];
    [imgV lt_setLeft:X(15) to:label save:YES];
    [imgV sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",KIMG,[_data objectForKey:@"bankImg"]]]];
    [imgV lt_setSize:CGSizeMake(X(26), Y(26)) save:YES];
    imgV.contentMode = UIViewContentModeScaleAspectFit;
    label = [[UILabel alloc]init];
    [view addSubview:label];
    [label lt_YcenterTo: nil save:YES];
    [label lt_setLeft:X(15) to:imgV save:YES];
    label.text = [NSString stringWithFormat:@"%@（%@）",_data[@"bank"],[_data[@"bankCard"] substringFromIndex:[_data[@"bankCard"] length]-4]];
    label.textColor = BLACK;
    label.font = [UIFont systemFontOfSize:16];
    UIView *view2 = [[UIView alloc]init];
    view2.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:view2];
    [view2 lt_Top:SunEdgesMake(Y(20), 0, 0, Y(50)) to:view save:YES];
    imgV = [[UIImageView alloc]init];
    [view2 addSubview:imgV];
    [imgV lt_YcenterTo:nil save:YES];
    [imgV lt_setLeft:X(15) to:nil save:YES];
    imgV.image = [UIImage imageNamed:@"third_money_tool"];
    label = [[UILabel alloc]init];
    [view2 addSubview:label];
    label.text = @"提现金额";
    label.textColor = GRAY;
    label.font = [UIFont systemFontOfSize:16];
    [label lt_YcenterTo:nil save:YES];
    [label lt_setLeft:X(48) to:nil save:YES];
    UILabel *label2 = [[UILabel alloc]init];
    [view2 addSubview:label2];
    label2.text = [self.money containsString:@"元"]?self.money:[NSString stringWithFormat:@"%.2f元",self.money.doubleValue];
    label2.textColor = BLACK;
    label2.font = [UIFont systemFontOfSize:16];
    [label2 lt_YcenterTo:nil save:YES];
    [label2 lt_setLeft:X(30) to:label save:YES];
    view = [[UIView alloc]init];
    view.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:view];
    [view lt_Top:SunEdgesMake(0, 0, 0, Y(50)) to:view2 save:YES];
    imgV = [[UIImageView alloc]init];
    [view addSubview:imgV];
    [imgV lt_YcenterTo:nil save:YES];
    [imgV lt_setLeft:X(15) to:nil save:YES];
    imgV.image = [UIImage imageNamed:@"third_getMoney_1"];
    label = [[UILabel alloc]init];
    [view addSubview:label];
    label.text = @"提现手续费";
    label.textColor = GRAY;
    label.font = [UIFont systemFontOfSize:16];
    [label lt_YcenterTo:nil save:YES];
    [label lt_setLeft:X(48) to:nil save:YES];
    _feeLabel = [[UILabel alloc]init];
    [view addSubview:_feeLabel];
    _feeLabel.text = @"0.00元";
    _feeLabel.textColor = BLACK;
    [_feeLabel lt_YcenterTo:nil save:YES];
    [_feeLabel lt_setLeft:X(30) to:label save:YES];
    _feeLabel.text = [NSString stringWithFormat:@"%.2f元",[[_data objectForKey:@"cashFee"]doubleValue]];
    UIButton *btn = [[UIButton alloc]init];
    [view addSubview:btn];
    [btn lt_setRight:X(15) to:nil save:YES];
    [btn lt_setSize:CGSizeMake(X(24), X(24)) save:YES];
    btn.layer.cornerRadius = X(12);
    [btn lt_YcenterTo:nil save:YES];
    btn.clipsToBounds = YES;
    [btn setBackgroundColor:RED forState:UIControlStateNormal];
    [btn setBackgroundColor:[HXColor colorWithHexString:@"ef4961"] forState:UIControlStateHighlighted];
    [btn setTitle:@"?" forState:UIControlStateNormal];
    [btn setTitleColor:WHITE forState:UIControlStateNormal];
    [btn addTarget:self action:@selector(question) forControlEvents:UIControlEventTouchUpInside];
    _timeLabel = [[UILabel alloc]init];
    [self.view addSubview:_timeLabel];
    _timeLabel.text = [NSString stringWithFormat:@"剩余免费次数：%d次",[[_data objectForKey:@"cashFreeNum"]intValue]];
    _timeLabel.font = [UIFont systemFontOfSize:12];
    _timeLabel.textColor = GRAY;
    [_timeLabel lt_setTop:Y(3) to:view save:YES];
    [_timeLabel lt_setLeft:X(15) to:nil save:YES];
    view2 = [[UIView alloc]init];
    view2.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:view2];
    [view2 lt_Top:SunEdgesMake(Y(20), 0, 0, Y(50)) to:_timeLabel save:YES];
    imgV = [[UIImageView alloc]init];
    [view2 addSubview:imgV];
    [imgV lt_YcenterTo:nil save:YES];
    [imgV lt_setLeft:X(15) to:nil save:YES];
    imgV.image = [UIImage imageNamed:@"third_money_tool_2"];
    label = [[UILabel alloc]init];
    [view2 addSubview:label];
    label.text = @"实际到账金额";
    label.textColor = GRAY;
    label.font = [UIFont systemFontOfSize:16];
    [label lt_YcenterTo:nil save:YES];
    [label lt_setLeft:X(15) to:imgV save:YES];
    _receiveMoneyLabel = [[UILabel alloc]init];
    [view2 addSubview:_receiveMoneyLabel];
    _receiveMoneyLabel.text = @"0.00元";
    _receiveMoneyLabel.textColor = RED;
    _receiveMoneyLabel.font = [UIFont systemFontOfSize:17];
    [_receiveMoneyLabel lt_YcenterTo:nil save:YES];
    [_receiveMoneyLabel lt_setLeft:X(30) to:label save:YES];
    _receiveMoneyLabel.text = [NSString stringWithFormat:@"%.2f元",self.money.floatValue - [[_data objectForKey:@"cashFee"]doubleValue]];
    UIButton *buton = [[UIButton alloc]init];
    [self.view addSubview:buton];
    [buton lt_Top:SunEdgesMake(Y(44), X(15), X(15), Y(44)) to:view2 save:YES];
    buton.clipsToBounds = YES;
    [buton setBackgroundColor:BLUE forState:UIControlStateNormal];
    [buton setBackgroundColor:[HXColor colorWithHexString:@"87CEFA"] forState:UIControlStateHighlighted];
    buton.layer.cornerRadius = 4;
    [buton setTitleColor:WHITE forState:UIControlStateNormal];
    buton.titleLabel.font = [UIFont systemFontOfSize:17];
    [buton setTitle:@"提交" forState:UIControlStateNormal];
    [buton addTarget:self action:@selector(submit) forControlEvents:UIControlEventTouchUpInside];
}

- (void)submit{
    NSString *url = [NSString stringWithFormat:@"%@%@",KURL,API_CASH];
    [[Sun shareSun]showActivity:self];
    [HttpRequest postURL:url withParam:@{@"money":self.money} success:^(id requestDic, NSString *msg) {
        [[Sun shareSun]hideActivity];
        JxWebVC *web = [[JxWebVC alloc]init];
        web.url = [requestDic objectForKey:@"url"];
        web.param = [requestDic objectForKey:@"data"];
        [self.navigationController pushViewController:web animated:YES];
    } failure:^(NSString *errorInfo, int code) {
        [[Sun shareSun]hideActivity];
        [[Sun shareSun]showMsg:errorInfo];
    }];
}

- (void)question{
    [[Sun shareSun]alertAlign:NSTextAlignmentLeft title:@"提现手续费" content:@"1、每月有3次免费提现次数\n2、超过3次后提现,按2元/笔进行收取提现手续费\n3、提现手续费是第三方支付平台向用户收取的费用" left:@"知道了" right:nil cancel:^{
        [[Sun shareSun]hideAll];
    } sure:nil To:self];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
